<?php

namespace LowCode\Naive;


use LowCode\Support\Fluent;

class DropdownOption extends Fluent
{
    public function __construct(string|int $key)
    {
        parent::__construct([]);
        $this->attributes['key'] = $key;
    }

    /**
     * 是否展示选项
     * @param string|bool $show
     * @return $this
     */
    public function show(string|bool $show): static
    {
        $this->attributes['show'] = $show;
        return $this;
    }

    /**
     * 显示的 label 值
     * @param string $label
     * @return $this
     */
    public function label(string $label): static
    {
        $this->attributes['label'] = $label;
        return $this;
    }

    /**
     * 类型
     * @param string $type "group" | "divider" | "render"
     * @return $this
     */
    public function type(string $type = "group" | "divider" | "render"): static
    {
        $this->attributes['type'] = $type;
        return $this;
    }

    /**
     * @param string $render () => VNodeChild
     * @return $this
     */
    public function render(string $render = "() => VNodeChild", string $id = null): static
    {
        $this->attributes['type'] = "render";
        $this->attributes['render'] = jsFn($render, $id);
        return $this;
    }

    /**
     * 支持通过 render 方法自定义 icon
     * @param string $icon
     * @param string|null $id
     * @return $this
     */
    public function icon(string $icon = "() => VNodeChild", string $id = null): static
    {
        $this->attributes['icon'] = jsFn($icon, $id);
        return $this;
    }

    /**
     * 是否禁用
     * @param bool $disabled
     * @return $this
     */
    public function disabled(bool $disabled): static
    {
        $this->attributes['disabled'] = $disabled;
        return $this;
    }


    /**
     * 是否禁用
     * @param array $props
     * @return $this
     */
    public function props(array $props): static
    {
        $this->attributes['props'] = $props;
        return $this;
    }

    public function jsonSerialize():array
    {
        return parent::jsonSerialize();
    }
}
